package com.longge;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/17
 * @描述
 */
public class MaxSatisfied {

    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int total = 0;
        int n = customers.length;
        for (int i = 0; i < n; i++) {
            if (grumpy[i] == 0) {
                total += customers[i];
            }
        }
        int increase = 0;
        for (int i = 0; i < minutes; i++) {
            increase += customers[i] * grumpy[i];
        }
        int max = increase;
        for (int i = minutes; i < n; i++) {
            increase += customers[i] * grumpy[i] - customers[i - minutes] * grumpy[i - minutes];
            max = Math.max(max, increase);
        }
        return total+max;

    }
}
